#!/bin/sh
# Start/stop/restart tinyerp-server.
# $Id: rc.tinyerp-server,v 1.0 2008/06/02
# Author: Heinz Wiesinger <hmwiesinger@gmx.at>
# ---------------------------------------------------------------------------

PIDFILE=/var/spool/tinyerp/tinyerp-server.pid
LOCKFILE=/var/lock/subsys/tinyerp-server
LOGFILE=/var/log/tinyerp/tinyerp-server.log

# Start tinyerp:
tinyerp_start() {
  if [ -x /usr/bin/tinyerp-server ]; then
    echo "Starting tinyerp server:  /usr/bin/tinyerp-server "
    if [ -e "$LOCKFILE" ]; then
        echo "tinyerp server already running!"
        echo "Please remove $LOCKFILE"
    else
        /usr/bin/tinyerp-server --pidfile=$PIDFILE --logfile=$LOGFILE \
          -c /etc/tinyerp/tinyerp-server.conf &
        touch $LOCKFILE
    fi
  fi
}

# Stop tinyerp:
tinyerp_stop() {
  echo "Stopping tinyerp-server"
  kill -TERM $(cat $PIDFILE) > /dev/null 2>&1
  rm -f $LOCKFILE
}

# Restart tinyerp:
tinyerp_restart() {
  tinyerp_stop
  sleep 1
  tinyerp_start
}

case "$1" in
'start')
  tinyerp_start
  ;;
'stop')
  tinyerp_stop
  ;;
'restart')
  tinyerp_restart
  ;;
*)
  echo "usage $0 start|stop|restart"
esac
